// src/stores/userStore.ts
import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
  state: () => ({
    isLoggedIn: false,
    username: '',
    userId: null as number | null,
  }),
  actions: {
    login(username: string, userId: number) {
      this.isLoggedIn = true;
      this.username = username;
      this.userId = userId;
      localStorage.setItem('username', username);
      localStorage.setItem('userId', String(userId));
    },
    logout() {
      this.isLoggedIn = false;
      this.username = '';
      this.userId = null;
      localStorage.removeItem('username');
      localStorage.removeItem('userId');
    },
  },
});